package Test_0916;

import Test_0813.Student;

import java.util.Locale;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 * Dare: 2024-09-16
 * Time: 8:29
 */
class S{
    public String name;
    public int age;

    public S(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test_0916 {
    public static void main(String[] args) {
        //去除前后两个空格
        String s=" a b c d ";
        String s1=s.trim();
        System.out.println(s1);
    }
    //截取
    public static void main7(String[] args) {
        String s1="abcdef";
        String s2=s1.substring(2);
        System.out.println(s2);
        String s4=s1.substring(2,4);//zuobiyoukai
        String s3=s1.substring(5);
        System.out.println(s4);
        System.out.println(s3);
    }
    //字符串的拆分
    public static void main6(String[] args) {
        String s1="name=1";
        //返回值是数组
        //如果是.分割加两个括号，多个分隔符，用竖线隔开，注意分隔符/
        String[] s2=s1.split("=");
        for (int i = 0; i < s2.length; i++) {
            System.out.println(s2[i]);
        }
    }
    //字符串的替换
    public static void main5(String[] args) {
        String s="aabababccd";
        //替换全部
        String s2=s.replace('a','c');
        String s3=s.replace("aa","cc");
        String s4=s.replace("aa","bcd");
        System.out.println(s);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
        //替换第一个
        String s5=s.replaceFirst("ab","bb");
        System.out.println(s5);
        String s6=s.replaceAll("ab","bb");
        System.out.println(s6);
    }
    //格式化%s,%lf,%f
    public static void main4(String[] args) {
        String s1=String.format("%d-%d-%d",2013,2,3);
        System.out.println(s1);
    }
    //字符串·数组
    public static void main3(String[] args) {
        String s1 = "lisi";
        char[] a = s1.toCharArray();
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
        String s3=new String(a);
        System.out.println(s3);
    }
    //大小写转换:只针对小写
    public static void main2(String[] args) {
        String s1="lisi";
        String s2=s1.toUpperCase();
        System.out.println(s1);
        System.out.println(s2);
        String s3="LiSi";
        System.out.println(s3.toUpperCase());
        String s4=s3.toUpperCase();
        String s5=s3.toLowerCase();
        System.out.println(s4);
        System.out.println(s5);
    }
    //转化
    public static void main1(String[] args) {
        String s1=String.valueOf(1234);
        String s2=String.valueOf(true);
        System.out.println(s1);
        System.out.println(s2);
        //序列化
        String s3=String.valueOf(new S("lisi",5));
        System.out.println(s3);
    }
}
